/* QtLua -- Lua bindings for Qt
   Copyright (C) 2011, Jarek Pelczar

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General
   Public License along with this library; if not, write to the
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301 USA

*/

#ifndef QLUASCRIPTEDITOR_P_H
#define QLUASCRIPTEDITOR_P_H

#include <QPlainTextEdit>
#include <QTextEdit>
#include <QPaintEvent>

class QLuaScriptEditExtraArea;

class QLuaScriptEditor : public QPlainTextEdit
{
    Q_OBJECT
public:
    explicit QLuaScriptEditor(QWidget *parent = 0);

    int currentLineNumber() const;
    void gotoLine(int lineNumber);

    int executionLineNumber() const;
    void setExecutionLineNumber(int lineNumber, bool error);
    void setExecutableLineNumbers(const QSet<int> &lineNumbers);
    bool isExecutableLine(int lineNumber) const;

    int extraAreaWidth() const;

protected:
    void paintEvent(QPaintEvent *e);
    void resizeEvent(QResizeEvent *e);

    void extraAreaPaintEvent(QPaintEvent *e);
    void extraAreaMouseEvent(QMouseEvent *e);
    bool extraAreaEvent(QEvent *e);

private slots:
    void updateExtraAreaWidth();
    void updateExtraArea(const QRect &, int);
    void highlightCurrentLine();

private:
    void updateExtraSelections();

private:
    friend class QLuaScriptEditExtraArea;
    QLuaScriptEditExtraArea * m_extraArea;
    int m_executionLineNumber;
    bool m_executionLineNumberHasError;
    QSet<int> m_executableLineNumbers;
    struct BreakpointData {
        BreakpointData() : enabled(true) {}
        bool enabled;
    };
    QHash<int, BreakpointData> m_breakpoints;
    int m_extraAreaToggleBlockNumber;
};

#endif // QLUASCRIPTEDITOR_P_H
